package permutation;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class makewords {

	List<Character> clist = new ArrayList<Character>();
	static int wordcount;

	public static void main(String[] args) {

		makewords mw = new makewords();

		String str = "AAEEIODFGHNRRRSSSTTW";

		String[] str_arr = { "SXTAN", "SEES", "OASIS", "STRAIGHT", "FORWARD",   //replace SXTAN by SATAN later 
				"SENSE", "FROG", "DREW", "SHIRTS" };

		List<Character> lc = mw.string_to_linkedList(str);
		// System.out.println(mw.clist);
		mw.countWords(lc, str_arr);

	}

	private List<Character> string_to_linkedList(String str) {

		char[] carr = str.toCharArray();
		for (int i = 0; i < carr.length; i++) {

			clist.add(carr[i]);

		}

		return clist;

	}

	private void countWords(List<Character> alphastr, String[] str_arr) {

		// List<Character> lc1 = lc;

		// iterating over the string array
		for (int i = 0; i < str_arr.length; i++) {

			// converting each string in the string array into a char array for
			// comparison
			 List<Character> copy_alphastr = alphastr;
			

			for (int j = 0; j < alphastr.size();) {

				for (int k = 0; k < str_arr[i].toCharArray().length;) {
					System.out.println(str_arr[i].toCharArray()[k]+""+j);

					
					

					if (str_arr[i].toCharArray()[k] == alphastr.get(j)) {
						alphastr.remove(j);

						k++;
						j = 0;
					}
					else if (j==alphastr.size()-1) {
                                      //undo any changes to the alphastring											
						i++;      //go to the next word
						j = 0;
						k=0;
						
					}
					else {

						j++;
					}

				}

			}

		}// string array loop ends here

	}

	private boolean wordFormed(char[] incarr, List<Character> lc) {

		List<Character> l = lc;

		for (int i = 0; i < incarr.length; i++) {

			for (int j = 0; j < l.size(); j++) {

				if (incarr[i] == l.get(j)) {

					l.remove(j);

				} else {
					return false;
				}

			}

		}

		return false;
	}

}
